

<template>
  <div >
    ({{minute}}分{{seconds}}秒)
  </div>
</template>

<script>
export default {
  name: 'interval',
  props:['expirationTime'],
  data () {
    return {
    minute:null,
      seconds: null,
      time_arr:[]
    }
  },
  computed: {
  
  },
  mounted () {
           let nowTime = (new Date().getTime())/1000;
            let updateTime = parseInt(this.expirationTime)/1000;
             let restTime = updateTime - nowTime > 0 ? updateTime - nowTime : 0;
                     let time=restTime;
                      let self = this;
                      if(restTime==0){
                          return;
                      }
                     this.time_arr.push(setInterval(function () {
                            if (time > -1) {
                                time--;
                                self.minute = Math.floor(time / 60);
                                self.seconds = Math.floor(time % 60);
                            } else {
                                clearInterval(time_arr);
                                self.minute = 0;
                                self.seconds = 0;
                            }
                        }, 1000));
  },
  methods: {
   
  },
  destroyed() {
      clearInterval(this.time_arr);
  },
}
</script>

<style scoped>

</style>